home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d8 / pdriver5.arc / PKTADDR.ASM < prev    next >
Assembly Source File  |  1989-12-17  |  6KB  |  327 lines

  1. ;  Russell Nelson, Clarkson University.  September 14, 1989
  2. ;  Copyright, 1989, Russell Nelson
  3.  
  4. ;   This program is free software; you can redistribute it and/or modify
  5. ;   it under the terms of the GNU General Public License as published by
  6. ;   the Free Software Foundation, version 1.
  7. ;
  8. ;   This program is distributed in the hope that it will be useful,
  9. ;   but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. ;   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  11. ;   GNU General Public License for more details.
  12. ;
  13. ;   You should have received a copy of the GNU General Public License
  14. ;   along with this program; if not, write to the Free Software
  15. ;   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  16.  
  17.     include    defs.asm
  18.  
  19. code    segment byte public
  20.     assume    cs:code, ds:code
  21.  
  22.     org    80h
  23. phd_dioa    label    byte
  24.  
  25.     org    100h
  26. start:
  27.     jmp    start_1
  28.  
  29. their_isr    dd    ?
  30. packet_int_no    db    ?,?
  31. ether_bdcst    db    EADDR_LEN dup(-1)    ;ethernet broadcast address.
  32. ether_addr    db    EADDR_LEN dup(-1)
  33. ether_byte    db    ?,?
  34.  
  35. handle        dw    ?
  36.  
  37. bogus_type    db    1,2,3,4,5,6,7,8        ;totally bogus type code.
  38.  
  39. signature    db    'PKT DRVR',0
  40. signature_len    equ    $-signature
  41. no_signature_msg    db    "No packet driver at that address",'$'
  42. usage_msg    db    "usage: pktaddr <packet_int_no> [<addr>]",'$'
  43. cant_set_msg    db    "Can't set our Ethernet address",'$'
  44. bad_addr_msg    db    "Bad address error",'$'
  45. bad_error_msg    db    "Unknown error",'$'
  46.  
  47. eaddr_msg    db    "My Ethernet address is ",'$'
  48. crlf_msg    db    CR,LF,'$'
  49.  
  50. usage_error:
  51.     mov    dx,offset usage_msg
  52. error:
  53.     mov    ah,9
  54.     int    21h
  55.     int    20h
  56.  
  57. start_1:
  58.     mov    si,offset phd_dioa+1
  59.     cmp    byte ptr [si],CR    ;end of line?
  60.     je    usage_error
  61.  
  62.     mov    di,offset packet_int_no
  63.     call    get_number
  64.     mov    cx,EADDR_LEN
  65.     mov    di,offset ether_addr
  66. start_2:
  67.     push    cx
  68.     push    di
  69.     mov    di,offset ether_byte
  70.     call    get_hex
  71.     mov    al,cl            ;remember the number in al.
  72.     pop    di
  73.     pop    cx
  74.     jc    start_3            ;exit if no number at all.
  75.     stosb                ;store a byte.
  76.     cmp    byte ptr [si],':'    ;skip colons between bytes.
  77.     jne    start_4
  78.     inc    si
  79. start_4:
  80.     loop    start_2
  81. start_3:
  82.  
  83.     mov    ah,35h            ;get their packet interrupt.
  84.     mov    al,packet_int_no
  85.     int    21h
  86.     mov    their_isr.offs,bx
  87.     mov    their_isr.segm,es
  88.  
  89.     lea    di,3[bx]
  90.     mov    si,offset signature
  91.     mov    cx,signature_len
  92.     repe    cmpsb
  93.     je    have_signature
  94.     mov    dx,offset no_signature_msg
  95.     jmp    error
  96. have_signature:
  97.  
  98.     push    ds
  99.     pop    es
  100.     mov    cx,EADDR_LEN
  101.     mov    si,offset ether_addr
  102.     mov    di,offset ether_bdcst
  103.     repe    cmpsb
  104.     je    get_mode        ;no address specified.
  105.  
  106.     mov    ah,25            ;set the ethernet address.
  107.     mov    di,offset ether_addr
  108.     mov    cx,EADDR_LEN
  109.     pushf
  110.     cli
  111.     call    their_isr
  112.     jc    bad
  113.     jmp    okay
  114. get_mode:
  115.     mov    ah,2            ;access all packets.
  116.     mov    al,1            ;Ethernet class.
  117.     mov    bx,-1            ;generic type.
  118.     mov    dl,0            ;generic number.
  119.     mov    cx,MAX_P_LEN        ;use the max type length.
  120.     mov    si,offset bogus_type
  121.     push    cs            ;es:di -> our receiver.
  122.     pop    es
  123.     mov    di,offset our_recv
  124.     pushf
  125.     cli
  126.     call    their_isr
  127.     jc    bad
  128.     mov    handle,ax
  129.  
  130.     mov    ah,6            ;get the ethernet address.
  131.     mov    di,offset ether_addr
  132.     mov    cx,EADDR_LEN
  133.     mov    bx,handle
  134.     pushf
  135.     cli
  136.     call    their_isr
  137.     jc    bad
  138.  
  139.     mov    dx,offset eaddr_msg
  140.     mov    ah,9
  141.     int    21h
  142.  
  143.     mov    cx,EADDR_LEN
  144.     mov    si,offset ether_addr
  145. print_addr:
  146.     push    cx
  147.     lodsb
  148.     mov    cl,' '            ;Don't eliminate leading zeroes.
  149.     call    byteout
  150.     pop    cx
  151.     cmp    cx,1
  152.     je    print_addr_1
  153.     mov    al,':'
  154.     call    chrout
  155. print_addr_1:
  156.     loop    print_addr
  157.  
  158.     mov    dx,offset crlf_msg    ;can't depend on DOS to newline for us.
  159.     mov    ah,9
  160.     int    21h
  161.  
  162.     mov    ah,3            ;release_type
  163.     mov    bx,handle
  164.     pushf
  165.     cli
  166.     call    their_isr
  167.     jc    bad
  168.  
  169.     jmp    short okay
  170.  
  171. bad:
  172.     cmp    dh,CANT_SET
  173.     jne    bad_1
  174.     mov    dx,offset cant_set_msg
  175.     jmp    error
  176. bad_1:
  177.     cmp    dh,BAD_ADDRESS
  178.     jne    bad_2
  179.     mov    dx,offset bad_addr_msg
  180.     jmp    error
  181. bad_2:
  182.     mov    dx,offset bad_error_msg
  183.     jmp    error
  184. okay:
  185.     int    20h
  186.  
  187.  
  188. our_recv:
  189.     or    ax,ax            ;first or second call?
  190.     jne    our_recv_1        ;second -- we ignore the packet
  191.     push    cs
  192.     pop    es
  193.     mov    di,offset our_buffer
  194. our_recv_1:
  195.     retf
  196.  
  197.  
  198.     public    get_number
  199. get_number:
  200.     mov    bp,10            ;we default to 10.
  201.     jmp    short get_number_0
  202.  
  203.     public    get_hex
  204. get_hex:
  205.     mov    bp,16
  206. ;get a hex number from [si], skipping leading blanks.
  207. ;return cy if there are no digits at all.
  208. ;return nc, bx:cx = number, and store cx at [di]
  209. get_number_0:
  210.     call    skip_blanks
  211.     call    get_digit        ;is there really a number here?
  212.     jc    get_number_3
  213.     or    al,al            ;Does the number begin with zero?
  214.     jne    get_number_4        ;no.
  215.     mov    bp,8            ;yes - they want octal.
  216. get_number_4:
  217.  
  218.     xor    cx,cx            ;get a hex number.
  219.     xor    bx,bx
  220. get_number_1:
  221.     lodsb
  222.     cmp    al,'x'            ;did they really want hex?
  223.     je    get_number_5        ;yes.
  224.     cmp    al,'X'            ;did they really want hex?
  225.     je    get_number_5        ;yes.
  226.     call    get_digit        ;convert a character into an int.
  227.     jc    get_number_2        ;not a digit (neither hex nor dec).
  228.     xor    ah,ah
  229.     cmp    ax,bp            ;larger than our base?
  230.     jae    get_number_2        ;yes.
  231.  
  232.     push    ax            ;save the new digit.
  233.  
  234.     mov    ax,bp            ;multiply the low word by ten.
  235.     mul    cx
  236.     mov    cx,ax            ;keep the low word.
  237.     push    dx            ;save the high word for later.
  238.     mov    ax,bp
  239.     mul    bx
  240.     mov    bx,ax            ;we keep only the low word (which is our high word)
  241.     pop    dx
  242.     add    bx,ax            ;add the high result from earlier.
  243.  
  244.     pop    ax            ;get the new digit back.
  245.     add    cx,ax            ;add the new digit in.
  246.     adc    bx,0
  247.     jmp    get_number_1
  248. get_number_5:
  249.     mov    bp,16            ;change the base to hex.
  250.     jmp    get_number_1
  251. get_number_2:
  252.     dec    si
  253.     mov    [di],cx            ;store the parsed number.
  254.     clc
  255.     ret
  256. get_number_3:
  257.     stc
  258.     ret
  259.  
  260.  
  261.     public    skip_blanks
  262. skip_blanks:
  263.     lodsb                ;skip blanks.
  264.     cmp    al,' '
  265.     je    skip_blanks
  266.     cmp    al,HT
  267.     je    skip_blanks
  268.     dec    si
  269.     ret
  270.  
  271.  
  272. get_digit:
  273. ;enter with al = character
  274. ;return nc, al=digit, or cy if not a digit.
  275.     cmp    al,'0'            ;decimal digit?
  276.     jb    get_digit_1        ;no.
  277.     cmp    al,'9'            ;. .?
  278.     ja    get_digit_2        ;no.
  279.     sub    al,'0'
  280.     clc
  281.     ret
  282. get_digit_2:
  283.     or    al,20h
  284.     cmp    al,'a'            ;hex digit?
  285.     jb    get_digit_1
  286.     cmp    al,'f'            ;hex digit?
  287.     ja    get_digit_1
  288.     sub    al,'a'-10
  289.     clc
  290.     ret
  291. get_digit_1:
  292.     stc
  293.     ret
  294.  
  295. byteout:
  296.     mov    ah,al
  297.     shr    al,1
  298.     shr    al,1
  299.     shr    al,1
  300.     shr    al,1
  301.     call    digout
  302.     mov    al,ah
  303. digout:
  304.     and    al,0fh
  305.     add    al,90h    ;binary digit to ascii hex digit.
  306.     daa
  307.     adc    al,40h
  308.     daa
  309.     cmp    al,cl            ;leading zero?
  310.     je    return
  311.     mov    cl,-1            ;no more leading zeros.
  312. chrout:
  313.     push    ax            ;print the char in al.
  314.     xchg    al,dl
  315.     mov    ah,2
  316.     int    21h
  317.     xchg    al,dl
  318.     pop    ax
  319. return:
  320.     ret
  321.  
  322. our_buffer    label    byte
  323.  
  324. code    ends
  325.  
  326.     end    start
  327.